package com.ruoyi.zhjd.laboratory.modules.asphaltLowTemperatureElongation.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.zhjd.common.util.ZhjdIotUtils;
import com.ruoyi.zhjd.laboratory.modules.asphaltLowTemperatureElongation.entity.AsphaltLowTemperatureElongationEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltLowTemperatureElongation.entity.AsphaltLowTemperatureElongationResEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltLowTemperatureElongation.service.AsphaltLowTemperatureElongationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 沥青低温延伸度试验仪
 *
 * @author sx
 * @email
 * @date 2023-07-11 16:37:53
 */
@RestController
@RequestMapping("laboratory/asphaltLowTemperatureElongation")
public class AsphaltLowTemperatureElongationController {

    @Autowired
    private AsphaltLowTemperatureElongationService asphaltLowTemperatureElongationService;

    /**
     * 列表
     */
    @RequestMapping("/page")
//    //
    public R page(@RequestParam Map<String, Object> params){
        IPage page = asphaltLowTemperatureElongationService.queryPage(params);
        return R.ok(page);
    }

    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
//    //
    public R find(@PathVariable("id") String id){
		AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation = asphaltLowTemperatureElongationService.getInfo(id);
        return R.ok(asphaltLowTemperatureElongation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //
    public R save(@RequestBody AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation){
		asphaltLowTemperatureElongationService.saveData(asphaltLowTemperatureElongation);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //
    public R update(@RequestBody AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation){
        asphaltLowTemperatureElongationService.updateData(asphaltLowTemperatureElongation);
        return R.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    //
    public R deleteOne(@PathVariable("id") String id){
        asphaltLowTemperatureElongationService.deleteOneData(id);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //
    public R delete(@RequestBody String[] ids){
        asphaltLowTemperatureElongationService.deleteData(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public R parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltLowTemperatureElongationService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return R.ok();
    }

    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    //
    public R changeSample(@RequestBody AsphaltLowTemperatureElongationResEntity asphaltLowTemperatureElongationRes){
        asphaltLowTemperatureElongationService.changeSample(asphaltLowTemperatureElongationRes);
        return R.ok();
    }
}
